package practice.w905;

public class RefArrayDemo {
    public static void main(String[] args) {
        Dog[] dogs=new Dog[3];
        dogs[0]=new Dog("小花",1,"橘色");
        dogs[1]=new Dog("小黑",2,"黑色");
        dogs[2]=new Dog("小白",1,"白色");
        dogs[2].age=3;//修改第三只狗的年龄
        dogs[1].name="格林";//修改第二只狗的名字
        for (int i = 0; i <dogs.length ; i++) {
            System.out.println(dogs[i].name);//遍历数组，输出每只狗的名字
            dogs[i].lookHome();//每只狗狗看家
            }

        Chick[] chicks=new Chick[2];
        chicks[0]=new Chick("小黄",1,"黄色");
        chicks[1]=new Chick("小红",1,"花");
        for (int i = 0; i <chicks.length ; i++) {
            System.out.println(chicks[i].name);
            chicks[i].layEggs();
        }

        Fish[] fishs=new Fish[2];
        fishs[0] =new Fish("小金",2,"金色");
        fishs[1] =new Fish("小白",1,"白色");
        for (int i = 0; i <fishs.length ; i++) {
            System.out.println(fishs[i].color);
            fishs[i].drink();



//            Dog[] dogs=new Dog[3];
//            dogs[0]=new Dog("小花",1,"橘色");
//            dogs[1]=new Dog("小黑",2,"黑色");
//            dogs[2]=new Dog("小白",1,"白色");
//            dogs[2].age=3;
//            dogs[1].name="格林";
//            for (int i = 0; i <dogs.length ; i++) {
//                System.out.println(dogs[i].name);
//                dogs[i].lookHome();
//            }
//
//            Chick[] chicks=new Chick[2];
//            chicks[0]=new Chick("小黄",1,"黄色");
//            chicks[1]=new Chick("小红",1,"花");
//            for (int i = 0; i <chicks.length ; i++) {
//                System.out.println(chicks[i].name);
//                chicks[i].layEggs();
//            }
//
//            Fish[] fishs=new Fish[2];
//            fishs[0] =new Fish("小金",2,"金色");
//            fishs[1] =new Fish("小白",1,"白色");
//            for (int i = 0; i <fishs.length ; i++) {
//                System.out.println(fishs[i].color);
//                fishs[i].drink();
        }
    }


}
